Function.RegisterNamespace("System.Web.EventStrategy");

System.Web.EventStrategy.Legacy=function(){    
    // IEventStrategy Methods
    this.Add=function(node,type,handler){
        type=normalizeType(type);
        node[type]=chainPredicate(handler,node[type]);  
    };
    
    this.Fire=function(node,type,context){
        if(Object.IsType(Function,node[type]))node[type](context||{});
    };

    this.Kill=function(event){
        return false;
    };

    this.Remove=function(node,type,handler){
        node[type]=null;
    };

    this.Suppress=function(event){
        //no-op
    };

    this.Target=function(event){
        return this;
    };
    
    // IStrategySpecification Members
    this.IsSatisfiedBy=function(candidate){
        return true;
    };
    
    // Private methods
    function normalizeType(type){
        type=type.toString().toLowerCase();
        if(!String.StartsWith(type,"on"))type="on"+type;
        return type;
    }
    
    function chainPredicate(handler,predicate){
        return function(){
            if(Object.IsType(Function,predicate))predicate.apply(this,arguments);
            handler.apply(this,arguments);
        }
    }
};

System.Web.EventStrategy.Legacy.Implement(System.Web.Event.IEventStrategy,"System.Web.EventStrategy.Legacy");
System.Web.EventStrategy.Legacy.Implement(System.Script.Strategy.IStrategySpecification,"System.Web.EventStrategy.Legacy");